package com.ruoyi.maode.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.maode.domain.dto.ApproveRequestDTO;
import com.ruoyi.maode.domain.dto.QueryFlowableDTO;
import com.ruoyi.maode.domain.vo.FlowableVO;
import com.ruoyi.maode.service.ApproveRequestProcessService;
import com.ruoyi.maode.service.PartBatchService;
import com.ruoyi.web.core.config.ResultDTO;
import com.ruoyi.web.util.PageQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhangwenqiang
 * @date 2025/07/13
 **/
@RestController
@RequestMapping("/flowable")
@Slf4j
public class FlowableController {

    @Autowired
    private ApproveRequestProcessService approveRequestProcessService;

    @Autowired
    private PartBatchService partBatchService;


    /**
     * 查询代办审批列表数据
     * @return
     */
    @PostMapping("/queryTask")
    public ResultDTO<Page<FlowableVO>> getTask(@RequestBody PageQuery<QueryFlowableDTO> dto) {
        return ResultDTO.success(approveRequestProcessService.getTask(dto));
    }

    /**
     * 获取代办审批详情的接口
     * @param taskId
     * @return
     */
    @GetMapping("/getTaskDetail/{taskId}")
    public ResultDTO getTaskDetail(@PathVariable("taskId") String taskId) {
        return ResultDTO.success(approveRequestProcessService.getTaskDetail(taskId));
    }

    /**
     * 获取已经完成的审批任务
     * @param dto
     * @return
     */
    @PostMapping("/getCompletedTask")
    public ResultDTO getCompletedTask(@RequestBody PageQuery<QueryFlowableDTO> dto) {
        return ResultDTO.success(approveRequestProcessService.getCompletedTask(dto));
    }

    /**
     * 获取历史审批节点数据
     * @param processInstanceId
     * @return
     */
    @GetMapping("/history/{processInstanceId}")
    public ResultDTO getHistory(@PathVariable("processInstanceId") String processInstanceId) {
        return ResultDTO.success(approveRequestProcessService.getHistory(processInstanceId));
    }

    /**
     * 审批流程
     * @param dto
     * @return
     */
    @PostMapping("/approve")
    public ResultDTO approve(@RequestBody ApproveRequestDTO dto) {
        approveRequestProcessService.approve(dto);
        return ResultDTO.success("审批成功！");
    }


}
